<?php 
/*gdo*/
header("Content-type: text/html; charset=utf-8;"); 
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';

session_start();
$pd=new pdo_mysql();

switch($_GET["tpl"]){
    case "sys_menu":
        $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
        $tbl=$pd->query("select tblname from ppf_tpl where tpl='".$_GET['tpl']."'")->fetchColumn(0);

        $result = array();
        $rs=$pd->query("select id,name,childnums,pid,ico,urls,flag from `".$tbl."` where pid=".$id." order by odx");
        while($row=$rs->fetch(PDO::FETCH_ASSOC)){
            $node = array();
            $node['id'] = $row['id'];
            $node['text'] = $row['name'];
            $node['ico'] = $row['ico'];	
            $node['urls'] = $row['urls'];	
            $node['flag'] = $row['flag'];	
            $node['state'] =$row['childnums'] ? 'closed' : 'open'; ;#has_child($pd,$row['id']) ? 'closed' : 'open';
            array_push($result,$node);
        }

        echo json_encode($result); 
        break;
    case "sys_area":
        $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
        $tbl=$pd->query("select tblname from ppf_tpl where tpl='".$_GET['tpl']."'")->fetchColumn(0);

        $result = array();
        $rs=$pd->query("select id,areaname,childnums,pid from `".$tbl."` where pid=".$id." order by odx");
        
        while($row=$rs->fetch(PDO::FETCH_ASSOC)){
            $node = array();
            $node['id'] = $row['id'];
            $node['text'] = $row['areaname'];	
            $node['state'] =$row['childnums'] ? 'closed' : 'open'; ;#has_child($pd,$row['id']) ? 'closed' : 'open';
            array_push($result,$node);
        }

        echo json_encode($result);
        break;
    case "sys_dict":
        $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
        $tbl=$pd->query("select tblname from ppf_tpl where tpl='".$_GET['tpl']."'")->fetchColumn(0);

        $result = array();
        $rs=$pd->query("select id,name,childnums,pid,dcode,flag from `".$tbl."` where pid=".$id." order by odx");
        while($row=$rs->fetch(PDO::FETCH_ASSOC)){
            $node = array();
            $node['id'] = $row['id'];
            $node['text'] = $row['name'];
            $node['dcode'] = $row['dcode'];		
            $node['flag'] = $row['flag'];	
            $node['state'] =$row['childnums'] ? 'closed' : 'open'; ;#has_child($pd,$row['id']) ? 'closed' : 'open';
            array_push($result,$node);
        }

        echo json_encode($result); 
        break;
}
$pd->close();
unset($pd);
unset($res);